**** This file replicates results from YouGov pre-election survey ****

use "YG_preelection_data.dta", clear

svyset [pw=weight]

*Gender Recode*
recode gender 2=1 1=0, gen(female)
label define female 0 "Male" 1 "Female"
label values female female
label variable female "Female"

*Income Recode*
gen incomecat=1 if faminc<=4
replace incomecat=2 if faminc>4 & faminc<10
replace incomecat=3 if faminc<97 & faminc>=10
replace incomecat=0 if faminc==97

label define incomecat 1 "Less than $40k" 2 "$40k - $100k" 3 "Over $100k"
label values incomecat incomecat

*Ideology Recode*
gen ideo3=ideo5
recode ideo3 1/2=1 3=2 4/5=3 6=4
label define ideo3 1 "liberal" 2 "moderate" 3 "conservative"
label val ideo3 ideo3
label var ideo3 "Ideology 3 point"
recode ideo5 1=0 2=.25 3=.5 4=.75 5=1 6=.

*Party ID Recode*
recode pid3 4/5=3
recode pid7 1=0 2=.17 3=.34 4=.5 5=.67 6=.84 7=1 8=.5

*Age Recode*
gen age=2016-birthyr
gen agecat=1 if age<30
replace agecat=2 if age>29 & age<55
replace agecat=3 if age>54

label define agecat 1 "18-29" 2 "30-54" 3 "55+"
label values agecat agecat

*Race Recode*
recode race 4/9=0, gen(racecat)
label values racecat RACE

*Education Recode*
recode educ 1/2=1 3/4=2 5=3 6=4, gen(educcat)
label define educcat 1 "HS or less" 2 "Some college" 3 "College degree" 4 "Postgraduate"
label values educcat educcat

recode educcat 3/4=1 1/2=0, gen(college)
label variable college "College degree"
label define college 0 "No degree" 1 "College degree"
label values college college

* Variable for South/Non-South
gen south=1 if inputstate==1 | inputstate==5 | inputstate==12 | inputstate==13 | inputstate==21 | inputstate==22 | inputstate==28 | inputstate==37 | inputstate==45 | inputstate==47 | inputstate==48 | inputstate==51 | inputstate==54 
recode south .=0

* DVs Recode
gen prezwleans=Q3
replace prezwleans=Q3lean if Q3==6
label values prezwleans LABB
recode prezwleans 1=0 2=1 3/7=., gen(prezvote)
recode prezwleans 3/5=3 6/7=., gen(prezvote2)
gen prezvote3=prezvote
replace prezvote3=0 if Q3nv==1
replace prezvote3=1 if Q3nv==2

gen likelyvoter=1 if (Q2==1 | Q2==7) & prezwleans<7


* Build sexism scale
 irt grm Q24_a -Q24_d
 predict sexism, latent
 gen sexism_scaled=(sexism+1.458568)/3.478209
 label var sexism_scaled "Hostile sexism scale"
 
* Build racism scale
recode Q35_a 1=6 2=5 3=4 4=3 5=2 6=1, gen(Q35_a_reversed)
recode Q35_b 1=6 2=5 3=4 4=3 5=2 6=1, gen(Q35_b_reversed)
irt grm Q35_a_reversed Q35_b_reversed Q35_d
predict racism, latent
gen racism_scaled=(racism+1.373585)/3.59874
 label var racism_scaled "Denial of racism scale"

* Build populism scale
recode Q36_a-Q36_c (5=1) (4=2) (2=4) (1=5)
irt grm Q36_a-Q36_c
predict populism, latent
gen populism_scaled=(populism+1.993257)/3.692719
 label var populism_scaled "Populism scale"

* Build authoritarian scale
recode Q30_a  Q30_c Q30_d (1=0) (2=1) 
recode Q30_b  (2=0)
irt 2pl Q30_a-Q30_d
predict authoritarianism, latent
gen authoritarianism_scaled=(authoritarianism+1.264572)/2.384125
label var authoritarianism_scaled "Authoritarianism Scale"
 
* Stereotypes
gen lazy_aa=Q34T1_a-Q34T1_b if racecat==1
gen intelligence_aa=Q34T2_a-Q34T2_b if racecat==1
gen violent_aa=Q34T3_a-Q34T3_b if racecat==1
gen values_aa=Q34T4_a-Q34T4_b if racecat==1
recode lazy_aa-values_aa (-10/0=0) (1/10=1)
irt 2pl lazy_aa-values_aa  if racecat==1
predict stereotypes_aa if racecat==1, latent
replace stereotypes_aa=(stereotypes_aa+.8352183)/2.1796923

gen lazy_lat=Q34T1_d-Q34T1_b if racecat==1
gen intelligence_lat=Q34T2_d-Q34T2_b if racecat==1
gen violent_lat=Q34T3_d-Q34T3_b if racecat==1
gen values_lat=Q34T4_d-Q34T4_b if racecat==1
recode lazy_lat-values_lat (-10/0=0) (1/10=1)
irt 2pl lazy_lat-values_lat  if racecat==1
predict stereotypes_lat if racecat==1, latent
replace stereotypes_lat=(stereotypes_lat+.7464715)/2.3030985

gen lazy_mus=Q34T1_c-Q34T1_b if racecat==1
gen intelligence_mus=Q34T2_c-Q34T2_b if racecat==1
gen violent_mus=Q34T3_c-Q34T3_b if racecat==1
gen values_mus=Q34T4_c-Q34T4_b if racecat==1
recode lazy_mus-values_mus (-10/0=0) (1/10=1)
irt 2pl lazy_mus-values_mus  if racecat==1
predict stereotypes_mus if racecat==1, latent
replace stereotypes_mus=(stereotypes_mus+.9630029)/2.2998209

 
* Economic satisfaction item
 
 recode Q15_c 5=1 4=.75 3=.5 2=.25 1=0, gen(econ_satisfaction)
label var econ_satisfaction "Economic Dissatisfaction"

 
**** Models in Table 2 (columns 1 and 2) and Figure 4
svy: probit prezvote sexism_scaled racism_scaled econ_satisfaction ideo5 pid7 female i.agecat college  i.incomecat i.racecat south if likelyvoter==1 

margins, at(econ_satisfaction=(0(.25)1))
marginsplot,  title("Economic Dissatisfaction") xtitle(" ") xlabel(0 `" "Most" "satisfied" "' 1 `" "Least" "satisfied  " "') ytitle("Prob. of voting for Trump") ylabel(.2 .4 .6 .8 1, angle(0)) saving(economic, replace) plotopt(lw(thick) msize(0) lc(black)) recastci(rarea) ciopt(col(gs10)) aspect(1)
margins, at(sexism_scale=(0(.2)1))
marginsplot,  title("Hostile Sexism") xtitle(" ") xlabel(0 `" "Least" "sexist" "' 1 `" "Most" "sexist" "') ytitle("Prob. of voting for Trump") saving(sex, replace)  plotopt(lw(thick) msize(0) lc(black)) recastci(rarea) ciopt(col(gs10)) aspect(1)
margins, at(racism_scale=(0(.2)1))
marginsplot,  title("Acknowledgement of Racism") xtitle(" ") xlabel(0 `" "Most acknowledging" "of racism" "' 1 `" "Most denying      " "of racism" "') ytitle("Prob. of voting for Trump")  saving(race, replace)  plotopt(lw(thick) msize(0) lc(black)) recastci(rarea) ciopt(col(gs10)) aspect(1)
graph combine economic.gph sex.gph race.gph, title("Pre-Election Survey") ycom col(3) iscale(.9) ysize(2) xsize(4.5) saving(fig4a, replace)
graph export econ_race_sex_scales.pdf, replace

svy: probit prezvote sexism_scaled racism_scaled econ_satisfaction ideo5 pid7 female i.agecat college  i.incomecat i.racecat south if likelyvoter==1 & race==1



**** Histograms in Figures 2 and 3

twoway histogram Q15_c if likelyvoter==1, discrete percent title("Pre-election survey" "Economic Satisfaction") barw(.5) bc(gs4) xlabel(,angle(45) val) xtitle(" ") aspect(1) plotr(lc(none)) saving(economy, replace)

twoway histogram sexism if likelyvoter==1, discrete percent title("Pre-election survey" "Hostile Sexism") xtitle(" ") w(.05) xlabel(-2 -1 0 1 2)  bc(gs4)  aspect(1) plotr(lc(none)) saving(sexism, replace)

twoway histogram racism if likelyvoter==1, discrete percent title("Pre-election survey" "Racism Denial") bc(gs4)  w(.05) xlabel(-2 -1 0 1 2)  xtitle(" ") aspect(1) plotr(lc(none)) saving(racism, replace)

twoway histogram Q15_c if likelyvoter==1 & racecat==1, discrete percent title("Pre-election survey" "Economic Satisfaction") barw(.5) bc(gs4) xlabel(,angle(45) val) xtitle(" ") aspect(1) plotr(lc(none)) saving(economy_whites, replace)

twoway histogram sexism if likelyvoter==1 & racecat==1, discrete percent title("Pre-election survey" "Hostile Sexism") xtitle(" ") w(.05) xlabel(-2 -1 0 1 2)  bc(gs4)  aspect(1) plotr(lc(none)) saving(sexism2, replace)

twoway histogram racism if likelyvoter==1 & racecat==1, discrete percent title("Pre-election survey" "Racism Denial") bc(gs4)  w(.05) xlabel(-2 -1 0 1 2)  xtitle(" ") aspect(1) plotr(lc(none)) saving(racism2, replace)


**** Models in Table 4

svy: reg prezvote college  if race==1 & likely==1
svy: reg prezvote college econ_satisfaction  if race==1 & likely==1
svy: reg prezvote college sexism_scaled if race==1 & likely==1
svy: reg prezvote college  racism_scaled  if race==1 & likely==1
svy: reg prezvote college sexism_scaled racism_scaled  if race==1 & likely==1


**** ROBUSTNESS CHECKS in Table A1

svy: probit prezvote sexism_scaled racism_scaled econ_satisfaction ideo5 pid7 female i.agecat college  i.incomecat if likelyvoter==1 & racecat==1 & stereotypes_aa~=. & stereotypes_lat~=. & stereotypes_mus~=.
svy: probit prezvote sexism_scaled racism_scaled econ_satisfaction authoritarianism_scaled populism_scaled stereotypes_aa stereotypes_lat stereotypes_mus ideo5 pid7 female i.agecat college  i.incomecat if likelyvoter==1 & racecat==1

svy: probit prezvote sexism_scaled racism_scaled econ_satisfaction ideo5 pid7 female i.agecat college  i.incomecat if likelyvoter==1 & racecat==1 & stereotypes_aa~=. & stereotypes_lat~=. & stereotypes_mus~=. & race==1
svy: probit prezvote sexism_scaled racism_scaled econ_satisfaction authoritarianism_scaled populism_scaled stereotypes_aa stereotypes_lat stereotypes_mus ideo5 pid7 female i.agecat college  i.incomecat if likelyvoter==1 & racecat==1




